﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using QLVT.Entity;
using QLVT.Config;

namespace QLVT.DAO
{
    class HoaDonXuatDAO:DAOBase
    {
        public DataSet GetAll()
        {
            return Select("select * from HoaDonXuat");
        }

        public HoaDonXuat GetById(String sohd)
        {
            HoaDonXuat hdx = null;
            SqlConnection conn = null;
            try
            {
                conn = Config.Config.getConnection();
                conn.Open();
                SqlCommand commnad = new SqlCommand("select * from HoaDonXuat where sohd = '" + sohd + "'", conn);
                SqlDataReader dataReader = commnad.ExecuteReader();
                if (dataReader.Read())
                {
                    hdx = new HoaDonXuat();
                    hdx.Sohd = dataReader.GetString(0);
                    hdx.NgayLap = dataReader.GetString(1);
                    hdx.Manv = dataReader.GetString(2);
                    hdx.Makh = dataReader.GetString(3);
                    return hdx;
                }
            }
            catch (Exception ex)
            {

            }
            finally
            {
                conn.Close();
               
            }
            return hdx;

        }

        public bool DeleteById(String sohd)
        {
            return Update("delete from HoaDonXuat where sohd = '" + sohd + "'");
        }

        public bool UpdateById(HoaDonXuat hdx)
        {
            String sql = "update HoaDonXuat "
                 + "set ngaylap = '" + hdx.NgayLap + "'"
                 + ", manv = '" + hdx.Manv + "'"
                 + ", makh = '" + hdx.Makh + "'"
                 + " where sohd = " + hdx.Sohd + "'";
                 
            return Update(sql);
        }
    }
}
